package org.base.core.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	
	public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	
	public static String formate(Date date, String pattern) {
		if(date == null) return null;
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	
	public static String formate(Date date) {
		return formate(date,DATETIME_PATTERN);
	}
	
	public static Date parse(String date,String pattern) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			return sdf.parse(pattern);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static Date parse(String date) {
		return parse(date,DATETIME_PATTERN);
	}

}
